package com.hag.equipment_server.controller;

import com.hag.equipment_server.netty.client.NettyClient;
import com.hag.equipment_server.util.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class AppController {

    @Autowired
    RedisUtils redisUtils;

    @Autowired
    NettyClient nettyClient;

    @GetMapping("test")
    public String test(){
        redisUtils.set("demo","1234");
        String demo = redisUtils.get("demo").toString();
        return demo;
    }

    @GetMapping("send")
    public void send(){
        nettyClient.sendMsg("hi");
    }

    /*type optical1 optical2 vibrate1 vibrate2*/
    @GetMapping("getData")
    public String getData(String type){
        String type1 = redisUtils.get(type).toString();
        return type1;
    }

    @GetMapping("getAllData")
    public Map getAllData(){
        Map<String,String> map = new HashMap<String,String>();
        String optical1 = redisUtils.get("optical1").toString();
        String optical2 = redisUtils.get("optical2").toString();
        String vibrate1 = redisUtils.get("vibrate1").toString();
        String vibrate2 = redisUtils.get("vibrate2").toString();
        String difference1 = redisUtils.get("difference1").toString();
        String difference2 = redisUtils.get("difference2").toString();
        String break1 = redisUtils.get("break1").toString();
        String break2 = redisUtils.get("break2").toString();

        map.put("optical1",optical1);
        map.put("optical2",optical2);
        map.put("vibrate1",vibrate1);
        map.put("vibrate2",vibrate2);
        map.put("difference1",difference1);
        map.put("difference2",difference2);
        map.put("break1",break1);
        map.put("break2",break2);

        return map;
    }
}
